{extend name='public/base' /}
{block name="content"}
<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body">
            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">

                    <div class="layui-inline">
                        <label class="layui-form-label">租户编号 ：</label>
                        <div class="layui-input-inline">
                            <input name="merchant_sn" class="layui-input" id="title" value="" type="text" placeholder="请输入商户编号">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">合同编号 ：</label>
                        <div class="layui-input-inline">
                            <input name="code" class="layui-input" id="code" value="" type="text" placeholder="请输入合同编号">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">业态：</label>
                        <div class="layui-input-inline">
                            <select name="activities"  lay-filter="activities" id="activities">
                                <option value="">请选择</option>
                                {volist name="activities" id="v1"}
                                <option value="{$v1.name}">{$v1.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">合同类型：</label>
                        <div class="layui-input-inline">
                            <select name="contract_type" id="contract_type">
                                <option value="" >请选择</option>
                                <option value="tenant">租赁合同</option>
                                <option value="lessee">写字楼</option>
                                <option value="booth">场地合同</option>
                                <option value="adplace">广告位</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">合同状态：</label>
                        <div class="layui-input-inline">
                            <select name="biz_state" id="biz_state">
                                <option value="" >请选择</option>
                                <option value="effect">已生效</option>
                                <option value="stopped">已终止</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">所属楼层：</label>
                        <div class="layui-input-inline">
                            <select name="lcName" id="lcName">
                                <option value="">请选择</option>
                                {volist name="lc" id="v1"}
                                <option value="{$v1.lcName}">{$v1.lcName}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">铺位类型：</label>
                        <div class="layui-input-inline">
                            <select name="positionType" id="positionType">
                                <option value="" >请选择</option>
                                <option value="shoppe">铺位</option>
                                <option value="office">单元</option>
                                <option value="adPlace">广告位</option>
                                <option value="booth">场地</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">店招名称 ：</label>
                        <div class="layui-input-inline">
                            <input name="name" class="layui-input"  value="" type="text" placeholder="请输入品牌名称">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">手机号 ：</label>
                        <div class="layui-input-inline">
                            <input name="mobile" class="layui-input" id="mobile" value="" type="text" placeholder="请输入手机号">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">公司名称 ：</label>
                        <div class="layui-input-inline">
                            <input name="company" class="layui-input" value="" type="text" placeholder="请输入公司名称">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn layui-btn-sm" data-id="table_id" lay-filter="search" lay-submit="">
                            <i class="layui-icon"></i>搜索
                        </button>
                        <button type="reset" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="layui-icon layui-icon-refresh"></i>{:__('Reset')}</button>
                        <button class="{:node('Merchant/export')} layui-btn layui-bg-black iconfont icon-daochu layui-btn-sm" lay-submit id="export" >导出</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table_id" lay-filter="table_id"></table>
        </div>
    </div>

</div>
{/block}

{block name="js"} <!--js处理区-->


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button type="button" lay-event="add"  class="layui-btn {:node('Merchant/addAdmin')} layui-btn-sm">添加商户</button>
       <!--	 <button type="button" lay-event="del"  class="layui-btn {:node('Admin/del')} layui-btn-sm layui-btn-danger">冻结商户</button> -->
        <button type="button" lay-event="reload"  class="layui-btn  layui-btn-sm  layui-btn-primary">刷新表格</button>
        <button type="button" id="import" class="layui-btn  layui-btn-sm">导入发票信息</button>
    </div>
</script>


<script type="text/html" id="operationTpl">
    <a href="javascript:;" class="layui-btn layui-btn-primary  layui-btn-xs {:node('Merchant/balance')}" data-title="余额明细" lay-event="balance"><i class="layui-icon">&#xe65e;</i></a>
    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('Merchant/add')}" data-title="编辑" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
<!--    <a href="javascript:;" class="layui-btn layui-btn-xs {:node('Merchant/add')}" data-title="查看详情" lay-event="detail"><i class="layui-icon">&#xe705;</i></a>-->
    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('Merchant/updatePassword')}" data-title="修改密码" lay-event="update"><i class="layui-icon">&#xe614;</i></a>
    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('Merchant/updateInvoice')}" data-title="编辑发票信息" lay-event="updateInvoice"><i class="layui-icon">&#xe624;</i></a>
    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('Merchant/addBalance')}" data-title="添加余额" lay-event="addBalance"><i class="layui-icon">&#xe654;</i></a>
    {{# if(d.status == 1){ }}
    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs {:node('Merchant/del')}" data-title="冻结" lay-event="del"><i class="layui-icon ">&#x1005;</i></a>
    {{# } }}
    {{# if(d.status == -1){ }}
    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs {:node('Merchant/undel')}" data-title="解冻" lay-event="undel"><i class="layui-icon ">&#x1007;</i></a>
    {{# } }}
    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs {:node('Common/resetPassword')}" data-title="重置密码" lay-event="resetPassword"><i class="layui-icon ">&#x1007;</i></a>
</script>

<script>
    layui.use(['element', 'table', 'form', 'jquery', 'lucky','opTable', 'upload'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky=layui.lucky;
        var opTable = layui.opTable;
        var upload = layui.upload;
        form.render();

        var myTables = table.render({
            elem: '#table_id',
            url:"{:url('index')}",
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports', 'print'],
            even: true, //开启隔行背景
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:20
                ,limits:[10,20,30,50]
            },
              // height: 'full-100',100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                { title: '', type: 'checkbox', fixed: true},
                { title: 'ID', field: 'id',width: 90},
                // { title: '组织', field: 'organization',templet:function (item){
                //         return item.organization.name+'/'+item.organizationOne.name
                //     }
                // },
                { title: '合同编码', field: 'code'},
                { title: '合同类型', field: 'contractType' ,templet:function (item) {
                    if(item.contract_type=='tenant'){
                        return '租赁合同';
                    }
                    if(item.contract_type=='lessee'){
                        return '写字楼';
                    }
                    if(item.contract_type=='booth'){
                        return '场地合同';
                    }
                    if(item.contract_type=='adplace'){
                        return '广告位';
                    }else {
                        return '暂无';
                    }
                }},
                // { title: '房间号', field: 'room_id'},
                { title: '店招', field: 'name'},
                { title: '公司名称', field: 'company'},
                { title: '租户名称', field: 'tenant_name'},
                { title: '租户编号', field: 'tenant_code'},
                { title: '负责人姓名', field: 'username'},
                { title: '手机号码', field: 'mobile' },
                { title: '期初余额', field: 'start_balance',templet:function (item) { return item.start_balance/100}},
                { title: '账户余额', field: 'balance',templet:function (item) { return (item.balance+item.frozen_balance)/100}},
                { title: '可用余额', field: 'balance',templet:function (item) { return item.balance/100}},
                // { title: '水电费冻结金额', field: 'frozen_balance',templet:function (item) { return item.frozen_balance/100}},
                // { title: '商户类型', field: 'type' ,  templet:function (item) { return item.type == 1?'常驻':'临户'}},
                { title: '铺位号', field: 'positions_code'},
                { title: '租赁面积', field: 'rent_area'},
                { title: '合同状态', field: 'biz_state' ,templet:function (item) {

                    if(item.biz_state=='effect'){
                        return '已生效';
                    }
                        if(item.biz_state=='canceled'){
                            return '已作废';
                        }
                        if(item.biz_state=='stopped'){
                            return '已终止';
                        }else {
                            return item.biz_state;
                        }
                    }
                },
                { title: '账户状态', field: 'status' ,templet:function (item) {
                        return item.status == -1?'冻结':'正常'
                    }
                },
                {templet: '#operationTpl', width: 360, align: 'center', title: '操作' ,fixed:'right'}
            ]],
            //  展开的列配置
            openCols: [
            {field: 'desc', title: '描述信息'}
            ],
            done: function (res) {
                layer.closeAll('loading');
            }
        });

        //导出事件
        $('#export').on('click',function () {
            var positionType = $('#positionType').val() ;
            var biz_state = $('#biz_state').val() ;
            var contract_type = $('#contract_type').val() ;
            var activities = $('#activities').val() ;
            var lcName = $('#lcName').val() ;
            var url = "{:url('export')}"+'?activities='+activities+ "&contract_type=" + contract_type +"&biz_state=" + biz_state+ "&positionType=" + positionType+"&lcName="+lcName;
            window.open(url);
        });
        //导入
        upload.render({
            elem: '#import',
            url: "{:url('import')}",
            accept: 'file', //普通文件
            multiple: false,
            exts: 'xlsx|xls', // 限制文件类型为 xlsx或xls
            done: function (data) {  // 成功的回调函数
                console.log(data)
                if(data.code==1){
                    alert(data.msg);
                }
            }
            , error: function (index, upload) {  // 失败的回调函数

            }
        });
        //导出时阻止页面刷新
        $(".layui-form").submit(function (e) {
            e.preventDefault();
        })

        /**
         * 监听单行工具操作
         */
        table.on('tool(table_id)', function (obj) {
            var data = obj.data;
            var _id=parseInt(data.id);
            var layEvent = obj.event;
            if(layEvent==="edit"){
                var urls="{:url('add')}?id="+_id;
                lucky.CreateOpenForm("编辑商户",urls);

            }else if(layEvent==="del"){
                lucky.FormatData(_id,"{:url('del')}","确认冻结？");
            }else if(layEvent==="balance"){
                var urls="{:url('balance')}?id="+_id;
                lucky.CreateOpenForm("余额明细",urls);
            }else if(layEvent==="undel"){
                var urls="{:url('undel')}";
                lucky.FormatData(_id,urls,'确认解冻 ？');
                return  false;
            }else if(layEvent==="addBalance"){
                var urls = "{:url('addBalance')}?id="+_id;
                lucky.CreateOpenForm("添加余额",urls);
            }else if(layEvent==="detail"){
                var urls = "{:url('detail')}?id="+_id;
                lucky.CreateOpenForm("账单明细",urls);
            }else if(layEvent==='resetPassword'){
                var urls = "{:url('Common/resetPassword')}?id="+_id + "&type=1";
                lucky.FormatData(_id,urls,'确认重置密码 ？');
            }else if(layEvent==='update'){
                var urls = "{:url('updatePassword')}?id="+_id;
                lucky.CreateOpenForm("修改登录密码",urls);
            } else if(layEvent==='updateInvoice'){
                var urls = "{:url('updateInvoice')}?id="+_id;
                lucky.CreateOpenForm("修改发票信息",urls);
            }
        });



        table.on('toolbar(table_id)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            if(obj.event==="add"){
                lucky.CreateOpenForm("添加商户","{:url('add')}");
                return false;
            }else if(obj.event==="close"){
                opTables.closeAll();
            }else if(obj.event==="open"){
                opTables.openAll();
            }else if(obj.event==="reload"){
                lucky.CreateReload();
            }else if(obj.event==="del"){
                var num=0;
                var id=[];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num<1) {
                    layer.msg("请选择一项",{time:1500});return false;
                }
                lucky.FormatData(id,"{:url('del')}",'确认冻结 ？');
                return  false;
            }
        });

        /**
         * 关键词搜索树
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch(obj.field);
            return false;
        });
    });

</script >

{/block}
